Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
How to solve "Message content must be a non-empty string" in node.js

Here is my code,

const { Client, Intents } = require('discord.js');
const mineflayer = require("mineflayer");
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

let sending = false
let chatData = []

let prefix = ".";
var settings = {
    username: "StilShem_tvink",
    host: "mstnw.net",
};

const bot = mineflayer.createBot(settings);

bot.on('kicked', (reason, loggedIn) => console.log(reason, loggedIn));
bot.on('error', err => console.log(err));

client.on("ready", async =>{
    console.log("Discord bot is online!")
})

bot.on("login", async =>{
    console.log("Minecraft bot is online!")
})

bot.on("message", message => {
    if(sending == true) {
        chatData.push(`${message}`)
    }
})

client.on("messageCreate", async msg => {
    let args = msg.content.split(" ").slice(1)

    if(msg.content.startsWith(".chat")) {
        let toSend = args.join(" ");
        if(!toSend) return msg.reply("No args")

        bot.chat(toSend)
        sending = true
        msg.channel.send(`${msg.author.tag} just sent ${toSend}`)

        setTimeout(() => {
            sending = false
            msg.channel.send(chatData.join("\n"))
            chatData = []
        }, 750)
    }
})

This code is for minecraft mineflayer with discord. And this code give me error.

C:\Users\ArtemiiYT\node_modules\discord.js\src\util\Util.js:414 if (!allowEmpty && data.length === 0) throw new error(errorMessage); ^

RangeError [MESSAGE_CONTENT_TYPE]: Message content must be a non-empty string. at Function.verifyString (C:\Users\ArtemiiYT\node_modules\discord.js\src\util\Util.js:414:49) at MessagePayload.makeContent (C:\Users\ArtemiiYT\node_modules\discord.js\src\structures\MessagePayload.js:113:22) at MessagePayload.resolveData (C:\Users\ArtemiiYT\node_modules\discord.js\src\structures\MessagePayload.js:128:26) at TextChannel.send (C:\Users\ArtemiiYT\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:168:61) at Timeout._onTimeout (C:\Users\ArtemiiYT\Desktop\Всё\AFK bot\AFKBOTDS\bot.js:46:25) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7) { [Symbol(code)]: 'MESSAGE_CONTENT_TYPE' }

Node.js v17.1.0

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I didn't go on my way to run the code, but I think the chatData array is empty. so when you try to .join("\n") all the elements inside it together, you just get an empty string which discord just rejects and you get an error. so you might want to check if there is anything in the array first.

if you are here for the code just add this in the interval function:

if(chatData.length < 1) {
  // maybe inform the user there is no new chat message?
  return;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!